package com.example.string;

public class StringFormatDate {
    //将秒转为时分秒
    public static void main(String[] args) {
        int second = 10000; //这是随便输入的秒值
        int hour = second / 3600; // 得到分钟数
        second = second % 3600;//剩余的秒数
        int minute = second / 60;//得到分
        second = second % 60;//剩余的秒

        System.out.println(String.format("%02d:%02d:%02d", hour, minute, second));
        String dateStr = "";
        if(hour > 0){
            dateStr = String.format("%d小时", hour);
        }
        if(minute > 0){
            dateStr += String.format("%d分", minute);
        }
        if(second > 0){
            dateStr += String.format("%d秒", second);
        }
        System.out.println(dateStr);

        System.out.println(String.format("%d小时%d分%d秒", hour, minute, second));
    }
}
